package github.sf.fw.tools.var;

import com.google.common.base.Objects;

/**
 * 变量
 */
public class Variable extends VariableDefine {
    private String val;

    public Variable() {
    }

    public Variable(String val, String variableName, VarType varType) {
        super(variableName, null, varType);
        this.val = val;
    }

    public String getVal() {
        return val;
    }

    public void setVal(String val) {
        this.val = val;
    }


    public static Variable fromVariableDefine(VariableDefine define, String val) {
        Variable variable = new Variable();
        variable.setVariableName(define.getVariableName());
        variable.setPropertyName(define.getPropertyName());
        variable.setType(define.getType());
        variable.setVal(val);
        return variable;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Variable variable = (Variable) o;
        return Objects.equal(variableName, variable.variableName) &&
                Objects.equal(propertyName, variable.propertyName) &&
                type == variable.type;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(variableName, propertyName, type);
    }
}
